package com.si.store;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import android.R.anim;
import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.content.Context;
import android.os.Bundle;
import android.support.v13.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;

import com.si.store.adapter.AdapterSearch;
import com.si.store.model.GamesAndApps;
import com.si.store.model.Variables;

@SuppressLint("InflateParams")
public class MainActivity extends Activity {
	SectionsPagerAdapter mSectionsPagerAdapter;
	ViewPager mViewPager;
	int positon;
	Menu menu;
	List<GamesAndApps> lisApps;
	Context context;
	 private static final String[] COUNTRIES = new String[] { "Belgium",
         "France", "France_", "Italy", "Germany", "Spain" };
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		final ActionBar actionBar = getActionBar();
		actionBar.setDisplayHomeAsUpEnabled(true);
		actionBar.setDisplayShowCustomEnabled(true);
		mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager());
		mViewPager = (ViewPager) findViewById(R.id.pager);
		mViewPager.setAdapter(mSectionsPagerAdapter);
		mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
					@Override
					public void onPageSelected(int position) {
						actionBar.setSelectedNavigationItem(position);
					}
				});
		//search
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayShowCustomEnabled(true);

        LayoutInflater inflator = (LayoutInflater) this
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View v = inflator.inflate(R.layout.searchview, null);

        actionBar.setCustomView(v);
        
        lisApps = new ArrayList<GamesAndApps>();
        for(int i=0; i < Variables.listApp.length; i++){
        	lisApps.add(Variables.listApp[i]);
        }
        AdapterSearch adapter = new AdapterSearch(this,
                R.layout.item_suggest, lisApps);
        AutoCompleteTextView textView = (AutoCompleteTextView) v
                .findViewById(R.id.editText1);
        textView.setAdapter(adapter);
        /*Log.e("TAg",lisApps.size()+"");
        AdapterSearch adapter = new AdapterSearch(MainActivity.this, R.layout.item_suggest, lisApps);
        AutoCompleteTextView autoComplete = (AutoCompleteTextView) v.findViewById(R.id.editText1);
        autoComplete.setAdapter(new ArrayAdapter<String>(getActionBar().getThemedContext(), android.R.layout.test_list_item, android.R.id.text1,
        		new String[]{"An", "An com","An kit"}));*/
        
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
//		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		int id = item.getItemId();
		switch (id) {
		case R.id.action_search:
			break;

		case R.id.action_share:

			break;
		}
		return super.onOptionsItemSelected(item);
	}
	
	/**
	 * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
	 * one of the sections/tabs/pages.
	 */
	public class SectionsPagerAdapter extends FragmentPagerAdapter {

		public SectionsPagerAdapter(FragmentManager fm) {
			super(fm);
		}

		@Override
		public Fragment getItem(int position) {
			switch (position) {
			case 0:
				return FragmentApp.newInstance(position + 1);

			}
			return null;

		}

		@Override
		public int getCount() {
			// Show 3 total pages.
			return 1;
		}

		@Override
		public CharSequence getPageTitle(int position) {
			Locale l = Locale.getDefault();
			switch (position) {
			case 0:
				return getString(R.string.App_games).toUpperCase(l);
			}
			return null;
		}
	}
}
